#include <boost/test/unit_test.hpp>

#include "flightnumber.h"

using namespace std;
using namespace aviation;

// This is a preprocessor macro that will make a nice test case for us and automatically make it
// run. The argument is what we're naming this test case. In this case it's the default constructor for
// our flight numbers.

BOOST_AUTO_TEST_CASE(TestFlightNumberDefaultConstructor)
{
	//Constructs an object with an appropriate string
	FlightNumber flightnumber1;
	BOOST_REQUIRE(flightnumber1.AsString() == "AA111");
}

BOOST_AUTO_TEST_CASE(TestFlightNumberStringConstructor)
{
	// First make a flight number with good input.
	aviation::FlightNumber flightNumber1(std::string("AB123"));

	// Make sure we get the right output.
	BOOST_REQUIRE(flightNumber1.AsString() == "AB123");

	// Try input that is too long but still valid.
	aviation::FlightNumber flightNumber2(std::string("AB12345"));

	// Check it's truncated properly.
	BOOST_REQUIRE(flightNumber2.AsString() == "AB123");

	// Try lowercase letters
	aviation::FlightNumber flightNumber3(std::string("aA123"));
	BOOST_REQUIRE(flightNumber3.AsString() == "AA123");

	aviation::FlightNumber flightNumber4(std::string("Az123"));
	BOOST_REQUIRE(flightNumber4.AsString() == "AZ123");

	// Try a bunch of bad inputs. Each one should cause an exception (error message) to be thrown,
	// so we use BOOST_CHECK_THROW to check this.
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("AB12")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("AAA23")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("A1234")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("AA23A")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("AAAAA")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("")), std::exception);
	BOOST_CHECK_THROW(aviation::FlightNumber(std::string("12345")), std::exception);
}

BOOST_AUTO_TEST_CASE(TestFlightNumberCopyConstructor)
{
	// Copies the flight number from another.
	FlightNumber flightnumber1("AB123");
	FlightNumber flightnumber2(flightnumber1);
	BOOST_REQUIRE(flightnumber1.AsString() == flightnumber2.AsString());

}

BOOST_AUTO_TEST_CASE(TestFlightNumberAssignmentOperator)
{
	// Assignment operator, copies from 'other'
	FlightNumber flightnumber1("AD456");
	FlightNumber flightnumber2;
	flightnumber2 = flightnumber1;
	BOOST_REQUIRE(flightnumber1.AsString() == flightnumber2.AsString());
}

BOOST_AUTO_TEST_CASE(TestFlightNumberComparisonEqualsOperator)
{
	//Returns true if they are the same, or false if they arent
	FlightNumber flightnumber1(string("BC321"));
	FlightNumber flightnumber2(string("BC321"));

	BOOST_REQUIRE(flightnumber1==flightnumber2);

}

BOOST_AUTO_TEST_CASE(TestFlightNumberComparisonNotEqualoperator)
{
	//Returns true if they are not the same, or false if they are
	FlightNumber flightnumber1(string("BF174"));
	FlightNumber flightnumber2(string("CD953"));

	BOOST_REQUIRE(flightnumber1!=flightnumber2);


}

BOOST_AUTO_TEST_CASE(TestFlightnumberAsString)
{
	//return the FlightNumber AsString as a string
    FlightNumber flightnumber1(string("CF621"));

	BOOST_REQUIRE(flightnumber1.AsString() == "CF621");

}